<?php
namespace app\admin\controller;

class AskAnswer extends Base{
	// 模糊搜索字段
	public $_like_field    = ['content'];
	// 回收站内容字段
	public $_recycle_field = 'content';
	
	public function win_detail(){
		$answer_id = $this->_get('answer_id', '对不起，操作有误！');
		$info = model('AskAnswer')->find($answer_id);

		$this->assign('info', $info);
		return $this->view();
	}
	public function del(){
		$ids       = $this->_post('ids/a');
		$answer_id = $this->_get('answer_id');
		if(!is_array($ids) && $answer_id){
			$data['is_delete']    = 1;
			$data['recycle_time'] = time();
			$where['answer_id'] = $answer_id;
			if(model('AskAnswer')->where($where)->update($data) == true){
				// 删除更新操作
				model('AskAnswer')->delete_update($answer_id);
				$this->success('删除成功!', '');
			}else{
				$this->error('删除失败!');
			}
		}
		elseif(is_array($ids)){
			$answer_ids = implode(',', $ids);
			$where['answer_id'] = array('in', $answer_ids);
			$data['is_delete']    = 1;
			$data['recycle_time'] = time();
			model('AskAnswer')->where($where)->update($data);
			// 删除更新操作
			model('AskAnswer')->delete_update($answer_ids);
			$this->success('批量删除成功!');
		}else{
			$this->error('请选择要删除内容!');
		}
	}
	//从回收站还原
	public function permit(){
		$ids       = $this->_post('ids/a');
		$answer_id = $this->_get('answer_id');
		
		$data['recycle_time'] = 0;
		$data['is_delete']    = 0;
		if(!is_array($ids) && is_numeric($answer_id)){
			$where['answer_id'] = $answer_id;
			if(model('AskAnswer')->where($where)->update($data) == true){
				// 还原更新操作
				model('AskAnswer')->permit_update($answer_id);
				$this->success('还原成功!', '');
			}else{
				$this->error('还原失败!');
			}
		}
		elseif(is_array($ids)){
			$answer_ids = implode(',', $ids);
			$where['answer_id'] = array('in', $answer_ids);
			model('AskAnswer')->where($where)->update($data);
			// 还原更新操作
			model('AskAnswer')->permit_update($answer_ids);
			$this->success('批量还原成功!');
		}
		else{
			$this->error('请选择要还原记录!');
		}
	}
}